package 
{	
	import flash.xml.XMLNode;
	dynamic public class ARow extends Object
	{
		public function ARow()
		{
			super();
		}
		
		public static function fromObject( p_obj:Object ):ARow{
			var result : ARow = new ARow();
			for( var prop:String in p_obj){
				result[prop] = p_obj[prop] || "";
			}
			return result;
		}
		
		public function fromXML(p_node:*):void {
			for(var prop:String in this){
				if(prop=="mx_internal_uid"){
					continue;
				}
				if (prop == "@text") {
					this[prop] = p_node.toString();
				}
				else {
					this[prop] = p_node.attribute(prop.replace("@", ""));
				}
			}
		}
		
		public function toXML( p_nodeName:String = "text"):XMLNode{
			var node :XMLNode = new XMLNode(1,p_nodeName);
			node.attributes = createAttributes()
			node.appendChild( new XMLNode( 3, this["@text"].toString() ) );
			return node;
		}
		
		public function get uid():String{
			return hasOwnProperty("@id") ? "@id" : hasOwnProperty("@key") ? "@key" : hasOwnProperty("@name") ? "@name" : hasOwnProperty("@uid") ? this["@uid"] : null;
		}

		public function clone():ARow{
			var result : ARow = new ARow();
			for(var prop:String in this){
				if(prop=="mx_internal_uid"){
					continue;
				}
				result[prop] = this[prop];
			}
			return result;
		}
		
		private function createAttributes():Object{
			var result : Object = new Object()
			for(var prop:String in this){
				if(prop=="mx_internal_uid" || prop.indexOf("@")==-1 || prop == "@text"){
					continue;
				}
				result[prop.replace("@","")] = this[prop];
			}
			return result;
		}
		
		public function toString():String{
			var result : String = "ARow: ";
			for(var prop:String in this){
				if(prop=="mx_internal_uid"){
					continue;
				}
				result += "\n"+prop +":"+ this[prop];
			}
			return result;
		}

	}
}